#include "unistd.h"
#include "stdio.h"
#include "sys/types.h"
int main(int argc, char const *argv[])
{
    printf("main进程(%d)开始执行\n",getpid());
    int value = 10;
    //创建子进程
    //失败：返回-1
    //成功：内核会依次执行父进程和子进程
    //如果是子进程，返回0
    pid_t pid = fork();
    if(pid == -1){
        printf("创建子进程失败\n");
    return -1;
    }else if (pid == 0){
        value++;
        printf("子进程(%d)开始执行,value:%d\n",getpid(),value);
    }
    else     {
        value--;
        printf("子进程(%d)开始执行,value:%d\n",getpid(),value);
    }
    printf("main进程(%d)结束执行\n",getpid());
    return 0;
}